<?php
namespace app\common\controller;
use think\Controller;
use think\Session;
class CardusdateNew extends Controller
{


    //数据字段处理



    /*
     * 创建会员卡
     * $arr 主要数据
     * $type 处理类型 接口/存储
     * $data 存储使用
     * $res 存储使用
     *
     */
    public function addcard($arr,$type,$data = '',$res = ''){
        $Platurl = new Platurl();
        $platurl = $Platurl->getagenturl('top_mid', Session::get('login_top_mid'));
        if ($type == 1){
            $data['card']['card_type'] = "MEMBER_CARD";                                                            //卡券类型 会员卡
            $data['card']['member_card']['background_pic_url'] = $arr['background_pic_url'];                       //卡面图片url
            //基础字段
            $data['card']['member_card']['base_info'] = $this->base_info($arr['base']);                             //卡券基本信息
            $data['card']['member_card']['prerogative'] = $arr['prerogative'];                                      //会员卡特权说明,限制1024汉字。
            $data['card']['member_card']['supply_bonus'] = $arr['supply_bonus'] == 1 ? true:false;                                          //是否积分
            $data['card']['member_card']['supply_balance'] = $arr['supply_balance'] == 1 ? true:false;                                      //是否余额
            //自定义栏目3
            if(isset($arr['is_cell1'])) {
                if ($arr['is_cell1'] == 1) {
                    $data['card']['member_card']['base_info']['custom_url_name'] = $arr['custom_cell1']['name'];
                    $data['card']['member_card']['base_info']['custom_url_sub_title'] = $arr['custom_cell1']['tips'];
                    $data['card']['member_card']['base_info']['custom_url'] = $arr['custom_cell1']['url'];
                } else {
                    $data['card']['member_card']['base_info']['custom_url_name'] = '';
                    $data['card']['member_card']['base_info']['custom_url_sub_title'] = '';
                    $data['card']['member_card']['base_info']['custom_url'] = '';
                }
            }

            //营销入口
            if(isset($arr['is_cell4'])) {
                if ($arr['is_cell4'] == 1) {
                    $data['card']['member_card']['base_info']['promotion_url_name'] = $arr['custom_cell4']['name'];
                    $data['card']['member_card']['base_info']['promotion_url'] = $arr['custom_cell4']['url'];
                    $data['card']['member_card']['base_info']['promotion_url_sub_title'] = $arr['custom_cell4']['tips'];
                } else {
                    $data['card']['member_card']['base_info']['promotion_url_name'] = '';
                    $data['card']['member_card']['base_info']['promotion_url'] = '';
                    $data['card']['member_card']['base_info']['promotion_url_sub_title'] = '';
                }
            }
            //积分字段
            if ($arr['supply_bonus'] == 1){
                if (isset($arr['bonus'])){
                    $data['card']['member_card']['bonus_rule'] = $this->bonus_rule($arr['bonus']);
                }
            }
            $data['card']['member_card']['supply_balance'] = $arr['supply_balance'] == 1 ? true:false;                                        //是否储值
            //自定义类目1
            if (isset($arr['custom_field1'])){
                if ($arr['is_field1'] == 1){
                    $data['card']['member_card']['custom_field1']['name_type'] = $arr['custom_field1']['name'];
                    if (isset($arr['custom_field1']['url'])){
                        $data['card']['member_card']['custom_field1']['url'] = $arr['custom_field1']['url'];
                    }

                }
            }
            //自定义类目1
            if (isset($arr['is_field2'])){
                if ($arr['is_field2'] == 1){
                    if (isset($arr['custom_field2']['name'])){
                        $data['card']['member_card']['custom_field2']['name'] = $arr['custom_field2']['name'];
                    }else{
                        $data['card']['member_card']['custom_field2']['name'] = $arr['custom_field2']['name'];
                    }

                    if (isset($arr['custom_field2']['url'])){
                        $data['card']['member_card']['custom_field2']['url'] = $arr['custom_field2']['url'];
                    }
                }
            }
            //自定义类目1
            if (isset($arr['is_field3'])){
                if ($arr['is_field3'] == 1){
                    if (isset($arr['custom_field3']['name'])){
                        $data['card']['member_card']['custom_field3']['name'] = $arr['custom_field3']['name'];
                    }else{
                        $data['card']['member_card']['custom_field3']['name'] = $arr['custom_field3']['name'];
                    }

                    if (isset($arr['custom_field2']['url'])){
                        $data['card']['member_card']['custom_field3']['url'] = $arr['custom_field3']['url'];
                    }
                }
            }
            //自定义类目1
            if(isset($arr['is_cell2'])){
                if ($arr['is_cell2'] == 1){
                    $data['card']['member_card']['custom_cell1']['name'] = $arr['custom_cell2']['name'];
                    $data['card']['member_card']['custom_cell1']['tips'] = $arr['custom_cell2']['tips'];
                    $data['card']['member_card']['custom_cell1']['url'] = $arr['custom_cell2']['url'];
                }
            }
            //自定义类目1
            if(isset($arr['is_cell3'])){
                if ($arr['is_cell3'] == 1){
                    $data['card']['member_card']['custom_cell2']['name'] = $arr['custom_cell3']['name'];
                    $data['card']['member_card']['custom_cell2']['tips'] = $arr['custom_cell3']['tips'];
                    $data['card']['member_card']['custom_cell2']['url'] = $arr['custom_cell3']['url'];
                }
            }
            //自定义类目3
//            if(isset($arr['is_cell3'])){
//                if ($arr['is_cell3'] == 1){
//                    $data['card']['member_card']['custom_cell3']['name'] = $arr['custom_cell3']['name'];
//                    $data['card']['member_card']['custom_cell3']['tips'] = $arr['custom_cell3']['tips'];
//                    $data['card']['member_card']['custom_cell3']['url'] = $arr['custom_cell3']['url'];
//                }
//            }
//            //会员卡激活
//            if($arr['activate'] == 1){$data['card']['member_card']['auto_activate'] = true;}                        //自动激活
//            if($arr['activate'] == 0){
            $data['card']['member_card']['wx_activate'] = true;                                                                             //一键激活
            $data['card']['member_card']['wx_activate_after_submit'] = true;                                                                //跳转型一键激活
            $data['card']['member_card']['wx_activate_after_submit_url'] = $platurl.'/mobile.php?s=/cardacitvate/cardfire/';                //跳转型一键激活地址
            //           }
            //会员卡折扣字段
            if ($arr['is_discount'] == 1){
                $data['card']['member_card']['discount'] = 100-$arr['discount'];                                            //几折
            }
            return $data;
        }
        if ($type == 2){
            $adata['mid'] = $arr['mid'];                                                                                      //商户ID
            $adata['top_mid'] = Session::get('login_top_mid');
            $adata['brand_name'] = $data['card']['member_card']['base_info']['brand_name'];
            $adata['card_type'] = 'MEMBER_CARD';                                                                    //类型
            $adata['logo_url'] = $data['card']['member_card']['base_info']['logo_url'];                             //LOGO
            $adata['title'] = $data['card']['member_card']['base_info']['title'];                                   //名称
            $adata['pic_url'] = $data['card']['member_card']['background_pic_url'];                                 //卡面图片url
            $adata['color'] = $arr['base']['color'];                                                           //颜色
            $adata['base_info'] = json_encode($data['card']['member_card']['base_info'],JSON_UNESCAPED_UNICODE);        //卡券基本信息
            $adata['card_id'] = $res['card_id'];                                                                                //卡券ID
            $adata['supply_bonus'] = $arr['supply_bonus'];
            $adata['is_dedu_cards'] = 1;
            $adata['supply_balance'] = $arr['supply_balance'];
            $adata['center_type'] = $arr['base']['is_center'];
            $adata['is_center'] = $arr['base']['is_center'];
            $adata['is_cell1'] = $arr['is_cell1'];
            $adata['is_cell2'] = $arr['is_cell2'];
            $adata['is_cell3'] = $arr['is_cell3'];
            $adata['is_cell4'] = $arr['is_cell4'];
            $adata['is_money'] = 1;         //开启余额
//            $adata['is_rank'] = 1;        //开启等级
            //        $adata['is_cell2'] = $arr['is_cell3'];
            $adata['is_field2'] = $arr['is_field2'];
            $adata['is_field3'] = $arr['is_field3'];
            $adata['is_locations'] = $arr['base']['is_locations'];
//            $adata['is_pro'] = $arr['base']['is_pro'];
//            $adata['is_custom'] = $arr['base']['is_custom'];
            $adata['is_center'] = $arr['base']['is_center'];
            if ($arr['base']['is_center'] == 1){
                if ($arr['base']['center'] == 9){
                    $adata['center_pay'] = 9;
                }else{
                    $adata['center_pay'] = 6;
                }
            }

            if ($arr['supply_bonus'] == 1) {
                if (isset($arr['bonus'])){
                    $adata['is_bonus'] = 1;
                    $adata['bonus_rule'] = json_encode($arr['bonus'], JSON_UNESCAPED_UNICODE);
                }
            }
//            if (isset($arr['is_field1'])){
//                if ($arr['is_field1'] == 1) {
//                    $adata['custom_field1'] = json_encode($arr['custom_field1'], JSON_UNESCAPED_UNICODE);
//                }
//            }
            if (isset($arr['is_field2'])) {
                if ($arr['is_field2'] == 1) {
                    $adata['custom_field2'] = json_encode($arr['custom_field2'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_field3'])) {
                if ($arr['is_field3'] == 1) {
                    $adata['custom_field3'] = json_encode($arr['custom_field3'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_cell1'])){
                if ($arr['is_cell1'] == 1) {
                    $adata['custom_cell1'] = json_encode($arr['custom_cell1'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_cell2'])){
                if ($arr['is_cell2'] == 1) {
                    $adata['custom_cell2'] = json_encode($arr['custom_cell2'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_cell3'])){
                if ($arr['is_cell3'] == 1) {
                    $adata['custom_cell3'] = json_encode($arr['custom_cell3'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_cell4'])){
                if ($arr['is_cell4'] == 1) {
                    $adata['custom_cell4'] = json_encode($arr['custom_cell4'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_discount'])) {
                if ($arr['is_discount'] == 1) {
                    $adata['discount'] = $arr['discount'];                                            //几折
                }
//                else{
//                    $adata['discount'] = 100;
//                }

            }
            $adata['prerogative'] = $arr['prerogative'];                                                                        //会员卡特权说明,限制1024汉字。
            $adata['statu'] = 0;                                                                                                //状态
            $adata['stocks'] = $data['card']['member_card']['base_info']['sku']['quantity'];                                    //库存
            $adata['activate'] = $arr['activate'];                                                                              //激活： 0/1  自动/一键
            $adata['wx_activate'] = true;                                                                                       //一键激活
            $adata['wx_activate_after_submit'] = true;                                                                          //跳转型一键激活
            $adata['wx_activate_after_submit_url'] = $platurl.'/mobile.php?s=/cardacitvate/cardfire/';                          //跳转型一键激活地址
            $adata['fire'] = $arr['activate'] == 1? 1:0;                                                                        //激活状态  需不需要提交激活字段
            $adata['create_time'] = time();
            return $adata;
        }
    }

    //修改会员卡
    /*
     * $arr 主要数据
     * $type 处理类型 接口/存储
     * $info 存储使用
     *
     * */
    public function editcard($arr,$type,$info="")
    {
        $Platurl = new Platurl();
        $platurl = $Platurl->getagenturl('top_mid', Session::get('login_top_mid'));
        if ($type == 1) {
            $data['card_id'] = $arr['card_id'];
            $data['member_card']['background_pic_url'] = $arr['background_pic_url'];                    //卡面图片url
            $data['member_card']['base_info'] = $this->ebase_info($arr['base']);                         //卡券基本信息
            //自定义栏目3
            if(isset($arr['is_cell1'])) {
                if ($arr['is_cell1'] == 1) {
                    $data['member_card']['base_info']['custom_url_name'] = $arr['custom_cell1']['name'];
                    $data['member_card']['base_info']['custom_url_sub_title'] = $arr['custom_cell1']['tips'];
                    $data['member_card']['base_info']['custom_url'] = $arr['custom_cell1']['url'];
                } else {
                    $data['member_card']['base_info']['custom_url_name'] = '';
                    $data['member_card']['base_info']['custom_url_sub_title'] = '';
                    $data['member_card']['base_info']['custom_url'] = '';
                }
            }

            //营销入口
            if(isset($arr['is_cell4'])) {
                if ($arr['is_cell4'] == 1) {
                    $data['member_card']['base_info']['promotion_url_name'] = $arr['custom_cell4']['name'];
                    $data['member_card']['base_info']['promotion_url'] = $arr['custom_cell4']['url'];
                    $data['member_card']['base_info']['promotion_url_sub_title'] = $arr['custom_cell4']['tips'];
                } else {
                    $data['member_card']['base_info']['promotion_url_name'] = '';
                    $data['member_card']['base_info']['promotion_url'] = '';
                    $data['member_card']['base_info']['promotion_url_sub_title'] = '';
                }
            }

            //         $data['member_card']['prerogative'] = $arr['prerogative'];
            $data['member_card']['supply_bonus'] = $arr['supply_bonus'] == 1 ? true:false;                                          //是否积分
            $data['member_card']['supply_balance'] = $arr['supply_balance'] == 1 ? true:false;                                      //是否余额
            //积分字段
            if ($arr['supply_bonus'] == 1){
                if (isset($arr['bonus'])){
                    $data['member_card']['bonus_rule'] = $this->bonus_rule($arr['bonus']);
                }
            }
            $adata['is_center'] = $arr['base']['is_center'];
            $arr['is_field2'] = 1;
            if ($arr['is_field2'] == 1){
//                $data['member_card']['custom_field2']['name_type'] = $arr['custom_field2']['name_type'];
                $data['member_card']['custom_field2']['url'] = $arr['custom_field2']['url'];
            }
            if (isset($arr['custom_field1'])){
                if ($arr['is_field1'] == 1){
                    $data['member_card']['custom_field1']['name_type'] = $arr['custom_field1']['name_type'];
                    if (isset($arr['custom_field1']['url'])){
                        $data['member_card']['custom_field1']['url'] = $arr['custom_field1']['url'];
                    }
                }
            }
            //自定义类目2
            if (isset($arr['is_field2'])){
                if ($arr['is_field2'] == 1){
                    if (isset($arr['custom_field2']['name_type'])){
                        $data['member_card']['custom_field2']['name_type'] = $arr['custom_field2']['name_type'];
                    }else{
                        $data['member_card']['custom_field2']['name'] = $arr['custom_field2']['name'];
                    }
                    if (isset($arr['custom_field2']['url'])){
                        $data['member_card']['custom_field2']['url'] = $arr['custom_field2']['url'];
                    }
                }
            }
            //自定义类目3
            if (isset($arr['is_field3'])){
                if ($arr['is_field3'] == 1){
                    if (isset($arr['custom_field3']['name_type'])){
                        $data['member_card']['custom_field3']['name_type'] = $arr['custom_field3']['name_type'];
                    }else{
                        $data['member_card']['custom_field3']['name'] = $arr['custom_field3']['name'];
                    }
                    if (isset($arr['custom_field3']['url'])){
                        $data['member_card']['custom_field3']['url'] = $arr['custom_field3']['url'];
                    }
                }
                if ($arr['is_field3'] == 2){
//                    $data['member_card']['custom_field3']['name_type']  = '';
                    $data['member_card']['custom_field3']['name'] = '';
                    $data['member_card']['custom_field3']['url'] = '';
                }
            }
            //自定义类目1
            if(isset($arr['is_cell2'])){
                if ($arr['is_cell2'] == 1){
                    $data['member_card']['custom_cell1']['name'] = $arr['custom_cell2']['name'];
                    $data['member_card']['custom_cell1']['tips'] = $arr['custom_cell2']['tips'];
                    $data['member_card']['custom_cell1']['url'] = $arr['custom_cell2']['url'];
                }else{
                    $data['member_card']['custom_cell1']['name'] = '';
                    $data['member_card']['custom_cell1']['tips'] = '';
                    $data['member_card']['custom_cell1']['url'] = '';
                }
            }
            //自定义类目1
            if(isset($arr['is_cell3'])){
                if ($arr['is_cell3'] == 1){
                    $data['member_card']['custom_cell2']['name'] = $arr['custom_cell3']['name'];
                    $data['member_card']['custom_cell2']['tips'] = $arr['custom_cell3']['tips'];
                    $data['member_card']['custom_cell2']['url'] = $arr['custom_cell3']['url'];
                }else{
                    $data['member_card']['custom_cell2']['name'] = '';
                    $data['member_card']['custom_cell2']['tips'] = '';
                    $data['member_card']['custom_cell2']['url'] = '';
                }
            }

            //自定义类目1
//            if(isset($arr['is_cell3'])){
//                if ($arr['is_cell3'] == 1){
//                    $data['member_card']['custom_cell3']['name'] = $arr['custom_cell3']['name'];
//                    $data['member_card']['custom_cell3']['tips'] = $arr['custom_cell3']['tips'];
//                    $data['member_card']['custom_cell3']['url'] = $arr['custom_cell3']['url'];
//                }
//            }
            //
            $data['member_card']['wx_activate'] = true;                                                                             //一键激活
            $data['member_card']['wx_activate_after_submit'] = true;                                                                //跳转型一键激活
            $data['member_card']['wx_activate_after_submit_url'] = $platurl.'/mobile.php?s=/cardacitvate/cardfire/';                //跳转型一键激活地址
            //END
            $data['member_card']['prerogative'] = $arr['prerogative'];                                  //会员卡特权说明,限制1024汉字。
            if ($arr['is_discount'] == 1) {
                $data['member_card']['discount'] = 100-$arr['discount'];
            }
            return $data;
        }
        if ($type == 2) {
            $base = json_decode($info['base_info'], true);                                       //原始基本信息
            $udata['logo_url_abs'] = $arr['logo_url_abs'];                                                    //logo绝对地址
            $udata['bg_url_abs'] = $arr['bg_url_abs'];                                                        //背景图片绝对地址
            $udata['logo_url'] = $arr['base']['logo_url'];                                                    //logo
            $udata['title'] = $arr['base']['title'];                                                   //名称
            $udata['pic_url'] = $arr['background_pic_url'];                                            //卡面图片url
            $udata['color'] = $arr['base']['color'];                                  //颜色
            $udata['brand_name'] = $base['brand_name'];
            //要修改的基本信息
            $udata['base_info'] = [
                "brand_name" => $base['brand_name'],                                                    //商家名称
                "logo_url" => $arr['base']['logo_url'],                                                        //logo
                "code_type" => $arr['base']['code_type'],                                                      //code展示类型
                "service_phone" => $arr['base']['service_phone'],                                              //客服电话
                "title" => $arr['base']['title'],                                                       //名称
                "color" => $arr['base']['color'],                                                       //颜色
                "get_limit" => $arr['base']['get_limit'],                                               //单人可领取
                "date_info" => array(                                                                   //时间类型
                    "type" => "DATE_TYPE_PERMANENT"
                ),
                "sku" => array(                                                                         //库存
                    "quantity" => $base['sku']['quantity']
                ),
                "notice" => $arr['base']['notice'],                                                     //卡券使用提醒
                "description" => $arr['base']['description'],                                           //卡券使用说明
                "center_title"=>$arr['base']['center_title'],
                "center_sub_title"=>$arr['base']['center_sub_title'],
                "center_url"=>$arr['base']['center_url'],
                'use_custom_code' => false,
                'can_give_friend' => true,
                //分享
                'can_share' => false,
                'need_push_on_view' => false,
                'use_all_locations' => true,
                //              "ontice" => $arr['base']['ontice'],
                //             "use_all_locations" => $base['use_all_locations'],
                //             "can_share" => $base['can_share'],
                //              "can_give_friend" => $base['can_give_friend'],
                //               "need_push_on_view" => $base['need_push_on_view'],
            ];
            $udata['base_info'] = json_encode($udata['base_info'],JSON_UNESCAPED_UNICODE);
            $udata['prerogative'] = $arr['prerogative'];                                                //特权说明
            $udata['is_center'] = $arr['base']['is_center'];
            $udata['is_cell1'] = $arr['is_cell1'];
            $udata['is_cell2'] = $arr['is_cell2'];
            $udata['is_cell3'] = $arr['is_cell3'];
            $udata['is_cell4'] = $arr['is_cell4'];
            $udata['is_field2'] = $arr['is_field2'];
            $udata['is_field3'] = $arr['is_field3'];
            $udata['is_locations'] = $arr['base']['is_locations'];
//            $udata['is_pro'] = $arr['base']['is_pro'];
//            $udata['is_custom'] = $arr['base']['is_custom'];
            $udata['is_center'] = $arr['base']['is_center'];
            if ($arr['base']['is_center'] == 1) {
                if ($arr['base']['center'] == 9) {
                    $udata['center_pay'] = 9;
                }else{
                    $adata['center_pay'] = 6;
                }
            }
            if ($arr['supply_bonus'] == 1) {
                $adata['is_bonus'] = 1;
                $udata['bonus_rule'] = json_encode($arr['bonus'], JSON_UNESCAPED_UNICODE);
            }
            if (isset($arr['is_field1'])){
                if ($arr['is_field1'] == 1) {
                    $udata['custom_field1'] = json_encode($arr['custom_field1'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_field2'])) {
                if ($arr['is_field2'] == 1) {
                    $udata['custom_field2'] = json_encode($arr['custom_field2'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_field3'])) {
                if ($arr['is_field3'] == 1) {
                    $udata['custom_field3'] = json_encode($arr['custom_field3'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_cell1'])){
                if ($arr['is_cell1'] == 1) {
                    $udata['custom_cell1'] = json_encode($arr['custom_cell1'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_cell2'])){
                if ($arr['is_cell2'] == 1) {
                    $udata['custom_cell2'] = json_encode($arr['custom_cell2'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_cell3'])){
                if ($arr['is_cell3'] == 1) {
                    $udata['custom_cell3'] = json_encode($arr['custom_cell3'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_cell4'])){
                if ($arr['is_cell4'] == 1) {
                    $udata['custom_cell4'] = json_encode($arr['custom_cell4'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_discount'])) {
                if ($arr['is_discount'] == 1) {
                    $udata['discount'] = $arr['discount'];                                            //几折
                }
//                else{
//                    $udata['discount'] = 100;
//                }
            }
            $udata['supply_bonus'] = $arr['supply_bonus'];
            $udata['supply_balance'] = $arr['supply_balance'];
            //          $udata['bonus_rule'] = json_encode($arr['bonus'], JSON_UNESCAPED_UNICODE);

            //         $udata['prerogative'] = $arr['prerogative'];                                                //会员卡特权说明
            $udata['update_time'] = time();
            return $udata;
        }
    }



    //基础字段

    //创建时基础字段
    public function base_info($arrs){
//       $arr['is_swipe_card'] = 1;
//       $arr['use_custom_code'] = $arr['use_custom_code'] == 1?true:false;
        $arr['color'] = $this->getcolor($arrs['color']);
        if (empty($arrs['get_limit'])){
            $arr['get_limit'] = 1;
        }else{
            $arr['get_limit'] = $arrs['get_limit'];
        }
        $arr['brand_name'] = $arrs['brand_name'];
        $arr['title'] = $arrs['title'];
        $arr['notice'] = $arrs['notice'];
        $arr['logo_url'] = $arrs['logo_url'];
        $arr['code_type'] = $arrs['code_type'];
        $arr['service_phone'] = $arrs['service_phone'];
        $arr['description'] = $arrs['description'];
        $arr['date_info']['type'] = $arrs['date_info']['type'];
        $arr['sku']['quantity'] = $arrs['sku']['quantity'];
        $arr['use_custom_code'] = false;
        //     $arr['can_give_friend'] = true;
        $arr['code_type'] = $arrs['code_type'];
        //分享
        $arr['can_share'] = false;
        $arr['can_give_friend'] = false;
        $arr['need_push_on_view'] = false;
//        //会员卡顶部中间按钮
        if($arrs['is_center'] == 1){
            if ($arrs['center'] == 9){
                $arr['pay_info']['swipe_card']['is_swipe_card'] = true;
                $arr['center_title'] = '';
                $arr['center_sub_title'] = $arrs['center_sub_title'];
                $arr['center_url'] = '';
            }else{
                $arr['center_title'] = $arrs['center_title'];
                $arr['center_sub_title'] = $arrs['center_sub_title'];
                $arr['center_url'] = $arrs['center_url'];
            }
        }else{
            $arr['center_title'] = '';
            $arr['center_sub_title'] = '';
            $arr['center_url'] = '';
        }

        //自定义类目1
//        if(isset($arr['is_cell2'])){
//            if ($arr['is_cell2'] == 1){
//                $data['member_card']['custom_cell2']['name'] = $arr['custom_cell2']['name'];
//                $data['member_card']['custom_cell2']['tips'] = $arr['custom_cell2']['tips'];
//                $data['member_card']['custom_cell2']['url'] = $arr['custom_cell2']['url'];
//            }
//        }
//        if(isset($arrs['is_cell3'])) {
//            if ($arrs['is_cell3'] == 1) {
//                $arr['custom_url_name'] = $arrs['custom_cell3']['name'];
//                $arr['custom_url_sub_title'] = $arrs['custom_cell3']['tips'];
//                $arr['custom_url'] = $arrs['custom_cell3']['url'];
//            } else {
//                $arr['custom_url_name'] = '';
//                $arr['custom_url_sub_title'] = '';
//                $arr['custom_url'] = '';
//            }
//        }
        //自定义类目1
//        if ($arrs['is_custom'] == 1){
//            $arr['custom_url_name'] = $arrs['custom_url_name'];
//            $arr['custom_url_sub_title'] = $arrs['custom_url_sub_title'];
//            $arr['custom_url'] = $arrs['custom_url'];
//        }else{
//            $arr['custom_url_name'] = '';
//            $arr['custom_url_sub_title'] = '';
//            $arr['custom_url'] = '';
//        }
//        //自定义类目2
//        if ($arrs['is_pro'] == 1){
//            $arr['promotion_url_name'] = $arrs['promotion_url_name'];
//            $arr['promotion_url'] = $arrs['promotion_url'];
//            $arr['promotion_url_sub_title'] = $arrs['promotion_url_sub_title'];
//        }else{
//            $arr['promotion_url_name'] = '';
//            $arr['promotion_url'] = '';
//            $arr['promotion_url_sub_title'] = '';
//        }
        //门店列表
        if ($arrs['is_locations'] == 1){
            $arr['use_all_locations'] = true;
        }
        if ($arrs['is_locations'] == 2){
            //    $arr['use_all_locations'] = false;
            $arr['location_id_list'] = $arrs['location_id_list'];
        }
//
//        $arr['pay_info']['swipe_card']['is_swipe_card'] = $arr['is_swipe_card'] == 1?true:false;
//        $arr['custom_url_name'] = "支持商家";
//        $arr['custom_url'] = "http://card.wunengkeji.com/index.php/substores";
//        $arr['custom_url_sub_title'] = "立即查看";
        return $arr;
    }



    //修改时基础字段
    public function ebase_info($arrs){
        $arr['logo_url'] = $arrs['logo_url'];                               //logo
        $arr['color'] = $this->getcolor($arrs['color']);                    //颜色
        $arr['code_type'] = $arrs['code_type'];
        $arr['notice'] = $arrs['notice'];                                   //使用提醒
//        $arr['brand_name'] = $arrs['brand_name'];                     //商户名称
        $arr['service_phone'] = $arrs['service_phone'];                     //客服电话
        $arr['description'] = $arrs['description'];                         //使用说明
        $arr['code_type'] = $arrs['code_type'];
        //会员卡顶部中间按钮
        if($arrs['is_center'] == 1){
            if ($arrs['center'] == 9){
                $arr['pay_info']['swipe_card']['is_swipe_card'] = true;
                $arr['center_title'] = '';
                $arr['center_sub_title'] = $arrs['center_sub_title'];
                $arr['center_url'] = '';
            }else{
                $arr['center_title'] = $arrs['center_title'];
                $arr['center_sub_title'] = $arrs['center_sub_title'];
                $arr['center_url'] = $arrs['center_url'];
            }
        }else{
            $arr['pay_info']['swipe_card']['is_swipe_card'] = false;
            $arr['center_title'] = '';
            $arr['center_sub_title'] = '';
            $arr['center_url'] = '';
        }

//        if(isset($arrs['is_cell3'])) {
//            if ($arrs['is_cell3'] == 1) {
//                $arr['custom_url_name'] = $arrs['custom_cell3']['name'];
//                $arr['custom_url_sub_title'] = $arrs['custom_cell3']['tips'];
//                $arr['custom_url'] = $arrs['custom_cell3']['url'];
//            } else {
//                $arr['custom_url_name'] = '';
//                $arr['custom_url_sub_title'] = '';
//                $arr['custom_url'] = '';
//            }
//        }

//        //自定义类目1
//        if ($arrs['is_custom'] == 1){
//            $arr['custom_url_name'] = $arrs['custom_url_name'];
//            $arr['custom_url_sub_title'] = $arrs['custom_url_sub_title'];
//            $arr['custom_url'] = $arrs['custom_url'];
//        }else{
//            $arr['custom_url_name'] = '';
//            $arr['custom_url_sub_title'] = '';
//            $arr['custom_url'] = '';
//        }
//        //自定义类目2
//        if ($arrs['is_pro'] == 1){
//            $arr['promotion_url_name'] = $arrs['promotion_url_name'];
//            $arr['promotion_url'] = $arrs['promotion_url'];
//            $arr['promotion_url_sub_title'] = $arrs['promotion_url_sub_title'];
//        }else{
//            $arr['promotion_url_name'] = '';
//            $arr['promotion_url'] = '';
//            $arr['promotion_url_sub_title'] = '';
        //     }
        //门店列表
        if ($arrs['is_locations'] == 1){
            $arr['use_all_locations'] = true;
        }
        if ($arrs['is_locations'] == 2){
            //    $arr['use_all_locations'] = false;
            $arr['location_id_list'] = $arrs['location_id_list'];
        }
        return $arr;
    }

    //积分字段
    public function bonus_rule($arrs){
        $arr['cost_money_unit'] = $arrs['cost_money_unit']*100;
        $arr['increase_bonus'] = $arrs['increase_bonus'];
        $arr['max_increase_bonus'] = $arrs['max_increase_bonus'];
        $arr['init_increase_bonus'] = $arrs['init_increase_bonus'];
        $arr['cost_bonus_unit'] = $arrs['cost_bonus_unit'];
        $arr['reduce_money'] = $arrs['reduce_money']*100;
        $arr['least_money_to_use_bonus'] = $arrs['least_money_to_use_bonus']*100;
        $arr['max_reduce_bonus'] = $arrs['max_reduce_bonus'];
        return $arr;
    }


    //高级字段
    private function advanced_info($arrs){
        $arr['abstract']['abstract'] = $arrs['abstract']['abstract'];
        $arr['abstract']['icon_url_list'] = [$arrs['abstract']['icon_url_list']];
        $arr['text_image_list'] = $this->advan_imglist($arrs['text_image_list']);
        return $arr;
    }

    //高级字段图文处理
    private function advan_imglist($arrs){
        if ($arrs){
//            $img = [];
//            $text = [];
            $img = $arrs['image_url'];
            $text = $arrs['text'];
            $data = [];
            if ($img) {
                foreach ($img as $k => $v) {
                    $data[$k]['image_url'] = $v;
                    $data[$k]['text'] = $text[$k];
                }
            }
            return $data;
        }

    }

    //颜色
    /*
     * 通过接口颜色编号获取实际色值
     *
     * */
    public function getcolor($arr){
        //    return $arr;
        switch($arr){
            //浅绿
            case '#63b359':
                $res = 'Color010';
                return $res;
                break;
            //
            case '#2c9f67':
                $res = 'Color020';
                return $res;
                break;
            //
            case '#509fc9':
                $res = 'Color030';
                return $res;
                break;
            //
            case '#5885cf':
                $res = 'Color040';
                return $res;
                break;
            //
            case '#9062c0':
                $res = 'Color050';
                return $res;
                break;
            //
            case '#d09a45':
                $res = 'Color060';
                return $res;
                break;
            //
            case '#e4b138':
                $res = 'Color070';
                return $res;
                break;
            //
            case '#ee903c':
                $res = 'Color080';
                return $res;
                break;
            //
            case '#f08500':
                $res = 'Color081';
                return $res;
                break;
            //
            case '#a9d92d':
                $res = 'Color082';
                return $res;
                break;
            //
            case '#dd6549':
                $res = 'Color090';
                return $res;
                break;
            //
            case '#cc463d':
                $res = 'Color100';
                return $res;
                break;
            //
            case '#cf3e36':
                $res = 'Color101';
                return $res;
                break;
            //
            case '#5E6671':
                $res = 'Color102';
                return $res;
                break;
            default:
                return 'Color030';
        }

    }


    public function getcolors($arr){
        //    return $arr;
        switch($arr){
            //浅绿
            case "#63b359":
                $res = '1';
                return $res;
                break;
            //
            case "#2c9f67":
                $res = '2';
                return $res;
                break;
            //
            case "#509fc9":
                $res = '3';
                return $res;
                break;
            //
            case "#5885cf":
                $res = '4';
                return $res;
                break;
            //
            case "#9062c0":
                $res = '5';
                return $res;
                break;
            //
            case "#d09a45":
                $res = '6';
                return $res;
                break;
            //
            case "#e4b138":
                $res = '7';
                return $res;
                break;
            //
            case "#ee903c":
                $res = '8';
                return $res;
                break;
            //
            case "#f08500":
                $res = '9';
                return $res;
                break;
            //
            case "#a9d92d":
                $res = '10';
                return $res;
                break;
            //
            case "#dd6549":
                $res = '11';
                return $res;
                break;
            //
            case "#cc463d":
                $res = '12';
                return $res;
                break;
            //
            case "#cf3e36":
                $res = '13';
                return $res;
                break;
            //
            case "#5E6671":
                $res = '14';
                return $res;
                break;
            default:
                return 'Color030';
        }

    }



}
